/* Copyright (c) 2009 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jessies.blogbaboon;

import e.util.*;
import java.awt.*;
import javax.swing.*;

public class UiUtils {
  private UiUtils() {
  }
  
  public static JToolBar makeToolBar(Action... actions) {
    JToolBar toolBar = new JToolBar();
    toolBar.setFloatable(false);
    
    for (int i = 0; i < actions.length; ++i) {
      if (i > 0) {
        // Toolbars look stupid on Mac OS 10.4 without this.
        // They also look stupid on GNOME without this as long as we don't have icons for all Actions.
        toolBar.addSeparator();
      }
      toolBar.add(UiUtils.makeToolBarButton(actions[i]));
    }
    
    return toolBar;
  }
  
  public static JButton makeToolBarButton(Action action) {
    JButton button = new JButton(action);
    button.setFocusable(false);
    button.setMnemonic(0); // Toolbar buttons shouldn't have mnemonics. (Maybe on Windows?)
    return button;
  }
  
  public static EditingWindow findEditingWindow() {
    final Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
    return (EditingWindow) SwingUtilities.getAncestorOfClass(EditingWindow.class, focusOwner);
  }
}
